<script setup>
import HomePannel from './HomePannel.vue';
import { getHomeNewAPI } from '@/api/home'
import { ref } from 'vue';

const newList = ref([])

const getNewList = async () => {
  const res = await getHomeNewAPI()
  newList.value = res
}

getNewList()

</script>

<template>
<div class="homenew">
  <div class="container">
    <home-pannel title="新鲜好物" desc="新鲜出炉 品质靠谱">
      <template #btn>
        <router-link class="btn">查看更多<i class="iconfont icon-arrow-right"></i></router-link>
      </template>
      <ul class="goodslist">
        <li v-for="item in newList" :key="item.id">
          <router-link :to="`/detail/${item.id}`">
            <img :src="`${item.picture}`" alt="">
            <p class="ellipsis">{{ item.name }}</p>
            <p class="price">￥{{ item.price }}</p>
          </router-link>
        </li>
      </ul>
    </home-pannel>
  </div>
</div>
</template>

<style lang="less" scoped>
.homenew {
  background-color: #fff;
  .btn {
    float: right;
    font-size: 16px;
    color: #a1a1a1;
    i {
      margin-left: 5px;
    }
  }
  .goodslist {
    margin-top: 40px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    li {
      background-color: #f0f9f4;
      width: 306px;
      margin-left: 5px;
      &:nth-child(1) {
        margin-left: 0;
      }
      a {
        display: block;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        img {
          width: 100%;
        }
        p {
          font-size: 22px;
          width: 100%;
          padding: 10px;
        }
        .price {
          color: @priceColor;
        }
      }
      &:hover {
        transform: translateY(-3px);
        box-shadow: 0 0 10px rgba(0, 0, 0, .3);
        transition: all .5s;
      }
    }
  }
}
</style>